home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / ClutWind / CLUTSample.inc1.a < prev    next >
Encoding:
Text File  |  1992-07-15  |  12.1 KB  |  333 lines  |  [TEXT/MPS ]

  1. *
  2. *    Apple Macintosh Developer Technical Support
  3. *
  4. *    CLUTSample
  5. *
  6. *    CLUTSample.inc1.a    -    Assembler Source
  7. *
  8. *
  9. *   Loosely based in the sample SAMPLE this program shows
  10. *   how to create a window and display on it the colors of the CLUT
  11. *    associated with the device the window sits on top of.
  12. *
  13. *    Left to the curious reader are some improvements such as, remembering the
  14. *    positions of each open window, so if you use this program to monitor your
  15. *    color tables it will position the windows in the last place you opened them.
  16. *    The treatment of direct devices is kind of 'casual' a better color display may 
  17. *    be appropriate. Last, it may be desireable to change the size of the color
  18. *    rectangles depending on the depth of the color table.
  19.  
  20. *    Check Sample sources for more detailed documentation.
  21.  
  22. * ----------- DEBUGGING INFORMATION -------------
  23. * This is used as a global switch to turn off the generation of debugging information.
  24. * The MACRO "DbgInfo" will generate this debugging information if set to 1.
  25.  
  26. DebuggerInfo    EQU    1
  27.  
  28.  
  29. * ================================================
  30. * --------   MACRO DEFINITIONS SECTION  ----------
  31. * ================================================
  32.  
  33. * ------------- GENERATE A PASCAL "CASE" OR "IF" SEQUENCE -------------
  34. * The following macro is used to generate a branch based on an index value
  35. * in a D-register with a value from 0 to N.  The branch is through a table
  36. * of relative addresses also generated by this macro. The macro is called
  37. * in one of two forms as follows:
  38.  
  39. *  {Form #1}    Case#        (Dreg,Default),case0,case1,...caseN
  40. *  {Form #2}    Case#.<size>    (Dreg,IF),(cst0,case0),...,(cstN,caseN)
  41.  
  42. * In Form #1, the "Default" specifies a label for any omitted case labels not
  43. * specified explicitly. The "case0", "case1",..."caseN" are case labels
  44. * identifying the various cases to be processed.  A case label may be omitted,
  45. * in which case the "Default" is used. The "Default" may also be omitted, but
  46. * in that case all case labels must be specified. If there are fewer case labels
  47. * than there are cases, but there are N possible values for the case index, the
  48. * proper number of trailing commas must be supplied to generate the defaults.
  49.  
  50. * In Form #2, the default is specified as the word "IF".  In this form the macro
  51. * generates a set of compares (CMPI's) and branches (BEQ) for each specified
  52. * case (there is no implicit default).    Each case is a constant/label pair.
  53. * The constant is compared (CMPI.W) and an branch is done (BEQ) to the case if
  54. * the Dreg equals the constant.  A size may be specified for all the branches
  55. * as a <size> attribute to the Case# call itself.  This must either be an "S"
  56. * or "W" to generate BEQ.S's or BEQ.W's.  The default is for "S".
  57.  
  58.         MACRO
  59.         Case#.&Size     &IdxDef
  60.         PRINT        Push,NoMDir     ; only list generated code
  61.         LCLA        &i        ; index to macro parameters
  62.         LCLA        &n        ; total number of macro parameters
  63.         LCLC        &Dreg,&Def    ; the Dreg and Default parameters
  64.         LCLC        &sz         ; the <size> value
  65.  
  66. &Dreg        SETC        &IdxDef[1]    ; pick off 1st opnd of sublist
  67. &Def        SETC        &IdxDef[2]    ; pick off 2nd opnd of sublist
  68. &n        SETA        &Nbr(&Syslist)    ; done for efficiency
  69. &i        SETA        2        ; cases start at 2nd parameter
  70.  
  71.  IF &UpCase(&Def) <> 'IF' THEN
  72. .* Create the jump table and the index value
  73. * -----------------------------------------------
  74.     ADD         &Dreg,&Dreg
  75.     MOVE        Case&SysNdx(&Dreg),&Dreg
  76.     JMP         Case&SysNdx(&Dreg)
  77.  
  78. Case&SysNdx
  79.     WHILE &i <= &n DO                ; process each case label
  80.        IF &SysList[&i] <> '' THEN
  81.         DC.W        &SysList[&i]-Case&SysNdx
  82.        ELSE
  83.         DC.W        &Def-Case&SysNdx
  84.        ENDIF
  85.        &i: SETA &i+1                 ; count off parameter
  86.     ENDWHILE
  87.  ELSE                            ; process (Cst,lbl) pairs
  88.  
  89. .* Create a series of CMPI and BEQ instructions
  90. * -----------------------------------------------
  91.     &Sz: SETC &Default(&Size, 'S')             ; setup size attribute
  92.     WHILE &i <= &n DO                ; process each (Cst,lbl) pair
  93.        CMPI        #&SysList[&i,1],&Dreg
  94.        BEQ.&Sz     &SysList[&i,2]
  95.        &i: SETA &i+1                ; count off parameter
  96.     ENDWHILE
  97.  ENDIF
  98.  
  99.         PRINT    Pop                 ; restore original print status
  100.         ENDM
  101.  
  102.  
  103. * ------------- GENERATE DEBUGGER SYMBOL INFORMATION -------------
  104. * This Macro will generate information for the debugger to read and display
  105. * as its module name.  This aids in debugging Asm code while looking at it
  106. * in the debugger.  This macro can only work if called at the end of stack
  107. * frame.  The appearance of the Macro statement in the source code must occur
  108. * immediately after the final "JMP   (A0)" or "RTS" instruction following the UNLINK.
  109. * Spaces may be included in the name, but no quotes are allowed.
  110.  
  111. *  {Form #1}    DbgInfo        ModName
  112. *  {Form #2}    DbgInfo.New    Really Long Module Name For MacsBug 6.0
  113.  
  114. * There are now two naming conventions used in MacsBug, Form #1 is the older MacsBug,
  115. * or TMON, and Form #2 is the newer MacsBug 6.0.  The older method would only
  116. * allow for a fixed length of eight characters.  If a shorter name is passed to
  117. * this Macro, it will extend the length to 8 chars with trailing spaces.
  118. * MacsBug 6.0 will now allow for a variable length C type string. This Macro will
  119. * create the proper DC statements and takes into account word alignment issues.
  120.  
  121.  
  122.         MACRO
  123.         DbgInfo.&Opt     &ModName#    ; the name to be used in the Debugger
  124.         PRINT        Push,NoMDir     ; Only list generated code
  125.         LCLC        &DbgName#    ; name to generate for MacsBug
  126.         LCLC        &DbgTemp    ; temporary name variable
  127.         LCLC        &New        ; variable used to test old vs. new
  128.         LCLC        &S        ; variable used to save PRINT state
  129.  
  130.  IF DebuggerInfo THEN                        ; do we want debugging info?
  131.     IF &ModName# ≠ '' THEN                    ; did we get a module name?
  132.     &New: SETC &UpCase(&Opt)                ; make option all upper case
  133.     IF (&New = 'NEW') THEN                    ; do we want new style?
  134.  
  135. .* Create the new MacsBug naming convention
  136. * -----------------------------------------------
  137.        &DbgTemp: SETC    &ModName#            ; generate new type symbols
  138.        IF &Len(&ModName#) < 32 THEN                ; if module name < 32 chars
  139.         IF &Len(&ModName#) // 2 = 0 THEN         ; add space if even so that...
  140.            &DbgTemp: SETC &Concat(&ModName#,' ')     ; string length plus length byte...
  141.         ENDIF                        ; will align to word boundary
  142.        &DbgName#: SETC &Concat(&Chr($80 + &Len(&ModName#)), &DbgTemp)
  143.        ELSE                            ; Length > 32 characters
  144.         IF &Len(&ModName#) // 2 = 1 THEN         ; add space if length is odd
  145.            &DbgTemp: SETC &Concat(&ModName#,' ')
  146.         ENDIF
  147.        &DbgName#: SETC &Concat(&Chr($80), &Chr(&Len(&ModName#)), &DbgTemp)
  148.        ENDIF
  149.     ELSE                            ; make it the older style
  150.  
  151. .* Create the older MacsBug naming convention
  152. * -----------------------------------------------
  153.        IF &Len(&ModName#) < 8 THEN                ; if module name < 8 chars
  154.         &DbgName#: SETC &Concat(&ModName#,'       ')    ; add at least 7 spaces
  155.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&DbgName#,1,1))), &SubStr(&DbgName#,2,7))
  156.        ELSE                            ; there are at least 8 chars
  157.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&ModName#,1,1))), &SubStr(&ModName#,2,7))
  158.        ENDIF
  159.     ENDIF
  160.  
  161. .* Create the DC.B with the debugger name, and include the NULs if new MacsBug option
  162. * -----------------------------------------------
  163.     &S: SETC &Setting('STRING')        ; preserve STRING status
  164.     IF &S ≠ 'ASIS' THEN            ; only change it if not already ASIS
  165.        STRING    ASIS
  166.        DC.B      '&DbgName#'
  167.        IF (&New = 'NEW') THEN
  168.         DC.W        0        ; fake literal size for new MacsBug
  169.        ENDIF
  170.        STRING    &S
  171.     ELSE
  172.        DC.B      '&DbgName#'
  173.        IF (&New = 'NEW') THEN
  174.         DC.W        0        ; fake literal size for new MacsBug
  175.        ENDIF
  176.     ENDIF
  177.    ENDIF
  178.  ENDIF
  179.  
  180.         PRINT    Pop             ; restore original print status
  181.         ENDM
  182.  
  183.  
  184. * ================================================
  185. * ---------------  EQUATE SECTION  ---------------
  186. * ================================================
  187.  
  188. * Some various EQUATES we'll use throughout the program.
  189. * -----------------------------------------------
  190. False        EQU    0        ; the value of False
  191. True        EQU    $0100        ; and you thought True = 1, HA!
  192. NIL        EQU    0        ; a NIL pointer to test against
  193.  
  194. ToolTrapBit    EQU    11        ; this bit is on for Tool traps
  195. WaitNextEvent    EQU    $A860        ; the WaitNextEvent trap number
  196. Unimplemented    EQU    $A89F        ; the Unimplemented trap number
  197. EnvironsVersion    EQU    1        ; this is the version of the SysEnvirons we want
  198. SleepValue    EQU    $7FFFFFFF    ; the sleeping time ($7FFFFFFF = MaxLongInt)
  199. SuspendResume    EQU    1        ; the suspend/resume event number of an OSEvent
  200. NoEvents    EQU    0        ; no events mask
  201. ExtremeNeg    EQU    -32768        ; for wide open rects and regions, see AdjustCursor
  202. ExtremePos    EQU    32767-1        ; -1 is because of a bug in regions, see AdjustCursor
  203.  
  204. * This is the minimum result from the following equation:
  205.  
  206. *    applLimit - applZone = minimum heap size
  207.  
  208. * for the application to run. It will insure that enough memory will
  209. * be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  210. * application, and still give the application some 'breathing room'.
  211. * To derive this number, we ran under a MultiFinder partition that was
  212. * our requested minimum size, as given in the 'SIZE' resource.
  213.  
  214. MinHeap        EQU    21*1024        ; minimum heap size in bytes
  215.  
  216. * This is the minimum exceptable result from PurgeSpace, when called
  217. * at initialization time, for the application to run. This number acts
  218. * as a double-check to insure that there really is enough memory for the
  219. * application to run, including what has been taken up already by
  220. * pre-loaded resources, the scrap, code, and other sundry memory blocks.
  221.  
  222. MinSpace    EQU    8*1024        ; minimum stack space in bytes
  223.  
  224.  
  225. * The following equates use for resources.  That's why they have a "r" in front.
  226. * -----------------------------------------------
  227. rMenuBar    EQU    128        ; application's menu bar
  228. rUserAlert    EQU    129        ; error alert for user
  229. rWindow        EQU    128        ; application's window
  230. rAboutAlert    EQU    128        ; about alert
  231.  
  232. * The following equates are for menu definitions, obviously.
  233. * -----------------------------------------------
  234. AppleMenu    EQU    128        ;  Apple menu
  235. AboutItem    EQU    1
  236.  
  237. FileMenu    EQU    129        ;  File menu
  238. NewItem        EQU    1
  239. CloseItem    EQU    2
  240. QuitItem    EQU    4
  241.  
  242. * -----------------------------------------------
  243. DITopLeft    EQU    $00500070    ; position of Disk Init dialogs
  244.  
  245. * ================================================
  246. * ----------------  RECORD TYPES  ----------------
  247. * ================================================
  248. * This section is declaring record structures.  These records are
  249. * templates.  No data is allocated at this point.  These are just
  250. * structures, similar to Pascal TYPEs.  They simply generate a list
  251. * of equate offsets.  Since none of these types are defined already
  252. * in the MPW AIncludes, we'll need to define them.
  253.  
  254. * ------------- MOUSE POINT TYPE -------------
  255.  
  256. Point        RECORD    0
  257. v        DS.W    1
  258. h        DS.W    1
  259.         ORG     v
  260. vh        DS.W    h
  261.         ENDR
  262.  
  263. * ------------- RECTANGLE TYPE -------------
  264.  
  265. Rect        RECORD    0
  266. Top         DS.W    1
  267. Left        DS.W    1
  268. Bottom        DS.W    1
  269. Right        DS.W    1
  270.         ORG     Top
  271. TopLeft        DS.L    1
  272. BotRight    DS.L    1
  273.         ENDR
  274.  
  275. * ------------- BITMAP TYPE -------------
  276.  
  277. BitMap        RECORD    0
  278. baseAddr    DS.L    1
  279. rowBytes    DS.W    1
  280. bounds        DS.L    Rect
  281.         ENDR
  282.  
  283. * ------------- EVENT RECORD TYPE -------------
  284.  
  285. EventRecord     RECORD    0
  286. What        DS.W    1
  287. Message     DS.L    1
  288. When        DS.L    1
  289. Where        DS.L    Point
  290. Modify        DS.W    1
  291.         ENDR
  292.  
  293. * ------------- THE QUICKDRAW WORLD -------------
  294.  
  295. MyQDGlobals    RECORD    0,DECREMENT
  296. thePort     DS.L    1
  297. White        DS.B    8
  298. Black        DS.B    8
  299. Gray        DS.B    8
  300. LtGray        DS.B    8
  301. DkGray        DS.B    8
  302. Arrow        DS.B    cursRec
  303. ScreenBits    DS.B    BitMap
  304. RandSeed    DS.L    1
  305.          ORG     -GrafSize
  306.          ENDR
  307.  
  308. * ------------- ALL OF OUR GLOBAL DATA -------------
  309. * Note the minimal amount of globals we're using.  Data such as
  310. * the EventRecord, WindowRecords, etc. do not belong in global data
  311. * allocation.  Only data that basically doesn't change through out the
  312. * execution of the program is considered global.  The boolean flags are
  313. * global, since they affect the state of the program at any given time.
  314. * Also note that any appearance of a DS outside of a stack frame will
  315. * be allocated off of A5 and becomes part of global data storage.
  316.  
  317. AppGlobals    RECORD    0        ; this is our global data storage
  318. Stopped        DS.W    1        ; boolean for the state of the light
  319. HasWNEvent    DS.W    1        ; boolean for WaitNextEvent trap, see ForceEnvirons
  320. InBackground    DS.W    1        ; boolean for if in background, see OSEvent
  321. StopRect    DS    Rect        ; rect for the Stop light, set from a resource
  322. GoRect        DS    Rect        ; rect for the Go light, set from a resource
  323. Mac        DS    SysEnvRec    ; the system environment record, see ForceEnvirons
  324.           ENDR
  325.  
  326. * ------------- CLUT Window Data TYPEs -------------
  327.  
  328. ClutWData    RECORD    0
  329. UpdateRtn    DS.L    1
  330. MouseDnRtn    DS.L    1
  331. ClutWDataSize    Equ    *
  332.         ENDR
  333.